<template>
	<view>
		<l-dragSort v-if="tableData.length>0" :list="tableData" @change="change"></l-dragSort>
		<view class="footer">
		  <view class="btn" @click="onSave">
		    保存
		  </view>
		</view>
	</view>
</template>

<script>
	import reqApi from "../../api/api.js";
	export default {
		data() {
			return {
				tableData: [],
				endList: []
			}
		},
		onShow() {
			this.getTable();
		},
		methods: {
			change(e) {
				console.log(e);
				this.endList = e;
			},
			onSave(){
        console.log("endList", this.endList);
				reqApi.editWeight({list: this.endList.length == 0?this.tableData:this.endList}).then(res=>{
					uni.showToast({
					  title: "保存成功",
					  icon: 'none',
					  mask: true,
					  duration: 1500,
					})
					setTimeout(()=>{
						uni.redirectTo({
							url: "/pages/mine/index"
						})
					}, 1500)
				})
			},
			getTable() {
				reqApi.sellerList({}).then(res => {
					this.tableData = res.data;
				})
			},
			asyncChange(item) {
				console.log("item", item.order_switch);
				// let order_switch = item.order_switch == 1? 0:1;
				reqApi.orderSwitch({
					id: item.id,
					order_switch: item.order_switch
				}).then(res => {
					console.log("修改成功");
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
